<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('MD定义列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>系统：</label>
			                    <select id="sysId" name="sysId" class="form-control m-b">
			                    	<option value=''></option>
			                        <option th:each="mdSys : ${mdSysList}" th:text="${mdSys.sysName}" th:value="${mdSys.sysId}"></option>
			                    </select>
                            </li>
                            <li>
                                <label>功能模块：</label>
			                    <select id="moduleId" name="moduleId" class="form-control m-b">
			                        <option value=''></option>
			                    </select>
                            </li>

                            <li>
                                <label>表代码：</label>
                                <input type="text" name="tableCode"/>
                            </li>
                            <li>
                                <label>表名称：</label>
                                <input type="text" name="tableName"/>
                            </li>


                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="metadata:table:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="metadata:table:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="metadata:table:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="metadata:table:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('metadata:table:edit')}]];
        var removeFlag = [[${@permission.hasPermi('metadata:table:remove')}]];
        var prefix = ctx + "metadata/table";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "MD定义",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'tableId',
                    title: '系统Id',
                    visible: false
                },
                {
                    field: 'tableCode',
                    title: '表代码'
                },
                {
                    field: 'tableName',
                    title: '表名称'
                },
                {
                    field: 'tableContent',
                    title: '表说明'
                },
                {
                    field: 'recordCount',
                    title: '数据量级'
                },
                {
                    field: 'recordCountUnit',
                    title: '数据量级单位'
                },

                {
                    field: 'moduleCode',
                    title: '功能模块代码'
                },
                {
                    field: 'moduleName',
                    title: '功能模块名称'
                },

                {
                    field: 'sysCode',
                    title: '系统代码'
                },
                {
                    field: 'sysName',
                    title: '系统名称'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.tableId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push("<a class='btn btn-success btn-xs " + editFlag + "' href='javascript:void(0)' onclick='columnInfo(" + row.tableId + ")'><i class='fa fa-edit'></i>字段信息</a>");
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.tableId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
   		$("#sysId").change(function () {
   			//alert($("#sysId").val())
   			$.ajax({
   				url: ctx + "metadata/module/list",
   				type: 'POST',
   				data: {
   					sysId: $("#sysId").val(),
   				},
   				success:function (data) {
   					$("#moduleId").empty();
   					$("#moduleId").append("<option value=''></option>");
   					for (var i = 0; i < data.rows.length; i++){
   						$("#moduleId").append("<option value='" + data.rows[i].moduleId + "'>" + data.rows[i].moduleName + "</option>");
   					}
   				}
   			});
   		});
   		
		/* 字段信息 */
		function columnInfo(tableId) {
		    var url =  'metadata/field/' + tableId;
		    $.modal.openTab("字段信息", url);
		}
    </script>
</body>
</html>